<style lang="less" scoped>
</style>
<template>
    <base-model
        @model-close="modelClose"
        @model-ok="modelOk"
        title="新建产品"
        :value="value"
        :loading="loading"
        @input="updateshow">
        <Form :model="form" :label-width="120" :ref="ref" :rules="rule">
            <FormItem label="产品编号：" prop="nub">
                <base-input v-model="form.nub" placeholder="请输入产品编号"></base-input>
            </FormItem>
            <FormItem label="客户产品编号：" prop="customernub">
                <base-input v-model="form.customernub" placeholder="请输入客户产品编号"></base-input>
            </FormItem>
            <FormItem label="产品名称：" prop="name">
                <base-input v-model="form.name" placeholder="请输入产品名称"></base-input>
            </FormItem>
            <FormItem label="产品规格：" prop="norm">
                <base-input v-model="form.norm" placeholder="请输入产品规格"></base-input>
            </FormItem>
            <FormItem label="产品单位：" prop="unit">
                <base-input v-model="form.unit" placeholder="请输入单位"></base-input>
            </FormItem>
        </Form>
    </base-model>
</template>
<script>
    export default {
        name: 'addproduct',
        props: {
            value: {
                type: Boolean,
                default: false
            }
        },
        data () {
            return {
                ref: 'addproduct',
                form: {
                    nub: '',
                    customernub: '',
                    name: '',
                    norm: '',
                    unit: ''
                },
                loading: true,
                rule: {
                    nub: this.rule.noNull('产品编号不能为空')
                }
            }
        },
        computed: {
        },
        methods: {
            updateshow (show) {
                this.$emit('input', show)
            },
            reset () {
                this.$refs[this.ref].resetFields();
                /*this.addUserForm = {
                    name: '',
                    password: '',
                    passwordcheck: '',
                    power: []
                }*/
            },
            modelClose () {
                this.reset()
                this.form = {
                    nub: '',
                    customernub: '',
                    name: '',
                    norm: '',
                    unit: ''
                }
            },
            modelOk () {
                console.log(this.form)
                this.$refs[this.ref].validate((valid) => {
                    if (valid) {
                        setTimeout(() => {
                            this.loading = false
                            setTimeout(() => {
                                this.loading = true
                            }, 100)
                            //this.reset()
                            this.form = {
                                nub: '',
                                customernub: '',
                                name: '',
                                norm: '',
                                unit: ''
                            }
                            this.$emit('input', false)
                            this.$Notice.success({
                                title: '产品添加成功',
                                desc: ''
                            });
                            this.$emit('input', false)
                        }, 2000);
                    } else {
                        this.loading = false
                        setTimeout(() => {
                            this.loading = true
                        }, 100)
                    }
                })

            }
        },
        components: {
        },
        mounted: function () {
        }
    };
</script>
